package com.zhangliuliu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhangliuliu.bean.RatsBean;
import com.zhangliuliu.dao.RatsDao;
import com.zhangliuliu.service.RatService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class RatServiceImpl extends ServiceImpl<RatsDao, RatsBean>implements RatService {
    @Override
    public void addRat(RatsBean ratsBean) {
        save(ratsBean);
    }

    @Override
    public RatsBean select(int id) {

        return getById(id);
    }

    @Override
    public IPage<RatsBean> cutByName(int pageNo, int pageSize, String name) {
     Page<RatsBean> page= new Page<>(pageNo,pageSize);
       QueryWrapper wrapper = new QueryWrapper();
        if (name!=null &&!name.equals("")){
         wrapper.eq("Rat_name",name);
     }
      IPage<RatsBean> iPage= this.page(page,wrapper);
        return iPage;
    }

    @Override
    public IPage<RatsBean> cut(int pageNo, int pageSize, String name, String food, String harm) {
        Page<RatsBean> Page = new Page<>(pageNo, pageSize);
        QueryWrapper wrapper = new QueryWrapper();
        if (name!=null &&!name.equals("")){
            wrapper.eq("Rat_name",name);
        }
        if (food!=null&&!food.equals("")){
            wrapper.eq("rat_food",food);
        }
        if (harm!=null&&!harm.equals("")){
            wrapper.eq("rat_harm",harm);
        }
        return this.page(Page,wrapper);
    }
}
